package org.oneblog.util;

import org.apache.commons.lang.StringUtils;
import org.oneblog.data.util.StringTools;

public class SizeBean {

    private int width;
    private int height;
    
    public SizeBean(String size) {
        initSize(size);
    }
    
    private void initSize(String size) {
        if(StringUtils.isBlank(size)) {
            return;
        }
        if(!size.startsWith("_") && size.length() > 1) {
            return;
        }
        size = size.substring(1);
        int index = size.indexOf('X');
        width = StringTools.getInt(size.substring(0, index), 0);
        height = StringTools.getInt(size.substring(index + 1), 0);
    }
    
    public boolean isSizeValidate() {
        return width > 0 && height > 0;
    }
    
    public int getWidth() {
        return width;
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public int getHeight() {
        return height;
    }

    public void setHeight(int height) {
        this.height = height;
    }
    
    public static void main(String[] args) {
        SizeBean  sizeBean = new SizeBean("_200X100");
        
        System.out.println(sizeBean.getWidth());
        System.out.println(sizeBean.getHeight());
    }
}
